home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000217_icon-group-sender _Thu Oct 21 08:00:13 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id HAA16777
  4.     for icon-group-addresses; Thu, 21 Oct 1999 07:58:13 -0700 (MST)
  5. Message-Id: <199910211458.HAA16777@baskerville.CS.Arizona.EDU>
  6. Date: Wed, 20 Oct 1999 19:21:24 -0700
  7. From: Blake Chapman <blakec@pacbell.net>
  8. Subject: List subscription insert/removal
  9. To: icon-group@optima.CS.Arizona.EDU
  10. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  11. Status: RO
  12.  
  13. Icon Project,
  14.  
  15. I am trying to figure out how to insert a new element into a list,
  16. and remove an element from the middle of a list (not the end).
  17. In answer to this question previously Gordon Peterson sent
  18. a reply.  I tried what he said and it doesn't work.
  19.  
  20. My original question, that he answered, was
  21. "I find no routines to pluck one element out of the middle of a list, or insert
  22. one in.  Are there such routines?".
  23.  
  24. His answer was:
  25. "Perhaps not, since those functions are really pretty trivial (you can use
  26. subscript ranges to specify sublists, making that kind of thing a simple
  27. expression).".
  28.  
  29. I assume he meant that I can insert an element into a list the same way
  30. I can insert a character into a string variable.  So I tried it, 4 ways; none
  31. of them worked, they all produce a run-time error and abort.  Here is
  32. the program.  Though I use mere charactes or 1-char strings as list
  33. elements, it is just to try out list manipulation...
  34.  
  35. procedure main()
  36.  local s  # it will be a list
  37.  
  38.  s:= ["a", "b", "c", "d"]
  39.  WriteL(s)   # this writes "abcd" as it should
  40.   # Next, I want to insert "x" as a list element between "b" and "c" ....
  41.   # didn't work:  s[3:3]:="x"
  42.   # didn't work:  s[3:3] := ["x"]
  43.   # didn't work:  s[3+:0] := ["x"]
  44.   s[3+:0] := "x"   # didn't work; I get a run-time error and program abort
  45.  WriteL(s)
  46. end
  47.  
  48. procedure WriteL(L)
  49.   local i, len
  50.   len := *L
  51.   i := 1
  52.   while  i <= len do  { writes(L[i])  ;  i +:= 1 }
  53.   write()
  54. end
  55.  
  56. I get the following error message when I run the above:
  57.  
  58. Run-time error 111
  59. File E:\icon\wsource\sublist.icn; Line 28   [the line:   s[3+:0] := "x" ]
  60. variable expected
  61. offending value: list_3 = []
  62. Traceback:
  63.    main()
  64.    {list_3 = [] := "x"} from line 28 in E:\icon\wsource\sublist.icn
  65.  
  66. Can you tell me how to accomplish what I want?
  67.  
  68. Thank You,
  69. Blake Chapman
  70.  
  71.  
  72.